package flc.ast.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.Random;

import flc.ast.R;
import flc.ast.databinding.FragmentStarBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link StarFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class StarFragment extends BaseNoModelFragment<FragmentStarBinding> {

    private boolean isShowAnswer = false;
    private String[] answer;

    @Override
    protected int onCreate() {
        return R.layout.fragment_star;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.ivLighten.setOnClickListener(this);
        answer = getResources().getStringArray(R.array.star_answer);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivLighten:
                if (isShowAnswer) {//重新问
                    mDataBinding.ivStarImg.setImageResource(R.drawable.aimg_wx1);
                    mDataBinding.ivLighten.setImageResource(R.drawable.aicon_dllmx);
                    mDataBinding.llStarTip.setVisibility(View.VISIBLE);
                    mDataBinding.tvStarAnswer.setVisibility(View.GONE);
                } else {
                    Random random = new Random();
                    int pos = random.nextInt(answer.length);
                    mDataBinding.tvStarAnswer.setText(answer[pos]);
                    mDataBinding.ivStarImg.setImageResource(R.drawable.aimg_wx2);
                    mDataBinding.ivLighten.setImageResource(R.drawable.aicon_cxw);
                    mDataBinding.llStarTip.setVisibility(View.INVISIBLE);
                    mDataBinding.tvStarAnswer.setVisibility(View.VISIBLE);
                }
                isShowAnswer = !isShowAnswer;
                break;
        }
    }

    @Override
    protected void initData() {

    }
}